package cn.java78.jdbc;

import cn.myschool.util.DBUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class UpdateStudetn {
    public static void main(String[] args) {
        //根据学号修改名字：

        Connection connection = null;
        Statement st = null;

        try {
            connection = DBUtil.getConnection();
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入学生的新名字：");
            String newName= sc.nextLine();
            //newName=newName.replace(",","\'");
           // newName=newName.replace("#","\\#");
            System.out.println("请输入学号");
            long stuno = sc.nextLong();
            String sql = "update s2 set sname='"+newName+"'  where stuno="+stuno;
            System.out.println(sql);
            st = connection.createStatement();
            int i = st.executeUpdate(sql);
            System.out.printf("xiugai了%d条", i);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(null, st, connection);
        }


    }
}
